package com.zzy.cms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zzy.cms.entity.CrmBanner;
import com.zzy.cms.mapper.CrmBannerMapper;
import com.zzy.cms.service.CrmBannerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author KAZU
 * @since 2023-01-18
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {
	
	@Autowired
	private CrmBannerMapper bannerMapper;
	
	/**
	 * 查询所有Banner,根据id进行降序排序，显示排序之后的前两条记录
	 * */
	@Cacheable(key = "'selectIndexList'", value = "banner")
	@Override
	public List<CrmBanner> selectAllBanner() {
		QueryWrapper<CrmBanner> wrapper = new QueryWrapper<>();
		wrapper.orderByDesc("id");
		// last可以拼接sql语句
		wrapper.last("limit 2");
		
		return bannerMapper.selectList(wrapper);
	}
}












